package com.ymatou.iapi.trading.operate.testcase;

import java.util.ArrayList;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.trading.operate.parameter.CustomsClearanceUnfreezeOrderReqBean;
import com.ymatou.iapi.trading.operate.service.CustomsClearanceUnfreezeOrderReqCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.database.sqlwapper.DefaultWapper;
import com.ymttest.utils.YMTDateUtil;
import com.ymttest.utils.constant.ECode;
/**
*清关解冻接口
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_CustomsClearanceUnfreezeOrderReq {
	private static CustomsClearanceUnfreezeOrderReqBean customsclearanceunfreezeorderreqBean;
	private static CustomsClearanceUnfreezeOrderReqCall customsclearanceunfreezeorderreqCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("清关解冻接口");
	}

	@Before
	public void caseUp() {
		customsclearanceunfreezeorderreqBean = new CustomsClearanceUnfreezeOrderReqBean();
		customsclearanceunfreezeorderreqCall = new CustomsClearanceUnfreezeOrderReqCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(customsclearanceunfreezeorderreqCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_CustomsClearanceUnfreezeOrderReq_001() {
		Logger.start(true, "批量清关解冻，成功");
		try {
			// 创建订单
			List<String> logisticsNos = new ArrayList<String>();
			DefaultWapper d = new DefaultWapper();
			int BusynessType = 1;
			int orderId = 0;
			for (int i = 0; i < 3; i++) {
				while (i == 0) {
					orderId = (int) d.selectOrderDispatched(BusynessType)
							.get(0).get("iOrderId");
					break;
				}

				String deliverSummary = (String) d
						.selectOrderDispatched(BusynessType).get(0)
						.get("billCode");
				logisticsNos.add(deliverSummary);
			}
			Logger.comment("前置数据准备结束");
			//参数
			customsclearanceunfreezeorderreqBean.setLogisticsNos(logisticsNos);
			//发送数据
			customsclearanceunfreezeorderreqCall
					.setData(customsclearanceunfreezeorderreqBean);
			customsclearanceunfreezeorderreqCall.callService();
			Logger.verifyEquals(ECode.SUCCESS,
					customsclearanceunfreezeorderreqCall.getCode(), "验证code");
			//数据库验证
			DefaultWapper database = new DefaultWapper();
			Logger.verifyEquals(false,
					database.selectOrderFrozenDetailByOrderId(orderId).get(0)
							.get("IsFrozen"), "验证是否已清关解冻");
			String updateTime0 = (String) YMTDateUtil.getObjectFormatTime(
					database.selectOrderFrozenByOrderId(orderId).get(0)
							.get("dUpdateTime"), "yyyy-MM-dd");
			String dFrozenTime = (String) YMTDateUtil.getObjectFormatTime(
					database.selectOrderFrozenByOrderId(orderId).get(0)
							.get("dFrozenTime"), "yyyy-MM-dd");
			String updateTime7 = YMTDateUtil.getBeforeOrNextDayStr(updateTime0,
					7);
			Logger.verifyEquals(dFrozenTime, updateTime7, "验证自动确认收货时间");

			Logger.verifyEquals(
					false,
					database.selectOrderFrozenByOrderId(orderId).get(0)
							.get("bFrozenAutoReceive"),
					"验证清关相关字段bFrozenAutoReceive");
			Logger.verifyEquals(
					false,
					database.selectOrderFrozenByOrderId(orderId).get(0)
							.get("bPause"), "验证清关相关字段");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_CustomsClearanceUnfreezeOrderReq_002() {
		Logger.start(true, "一个单号清关解冻，成功");
		try {
			List<String> logisticsNos = new ArrayList<String>();
			DefaultWapper d = new DefaultWapper();
			int BusynessType = 1;
			int orderId = (int) d.selectOrderDispatched(BusynessType).get(0)
					.get("iOrderId");
			//Logger.debug(orderId);
			String deliverSummary = (String) d
					.selectOrderDispatched(BusynessType).get(0).get("billCode");
			logisticsNos.add(deliverSummary);
			Logger.comment("前置数据准备结束");
			//参数
			customsclearanceunfreezeorderreqBean.setLogisticsNos(logisticsNos);
			//发送数据
			customsclearanceunfreezeorderreqCall
					.setData(customsclearanceunfreezeorderreqBean);
			customsclearanceunfreezeorderreqCall.callService();
			Logger.verifyEquals(ECode.SUCCESS,
					customsclearanceunfreezeorderreqCall.getCode(), "验证code");
			//数据库验证
			DefaultWapper database = new DefaultWapper();
			Logger.verifyEquals(false,
					database.selectOrderFrozenDetailByOrderId(orderId).get(0)
							.get("IsFrozen"), "验证是否已清关解冻");
			String updateTime0 = (String) YMTDateUtil.getObjectFormatTime(
					database.selectOrderFrozenByOrderId(orderId).get(0)
							.get("dUpdateTime"), "yyyy-MM-dd");
			String dFrozenTime = (String) YMTDateUtil.getObjectFormatTime(
					database.selectOrderFrozenByOrderId(orderId).get(0)
							.get("dFrozenTime"), "yyyy-MM-dd");
			String updateTime7 = YMTDateUtil.getBeforeOrNextDayStr(updateTime0,
					7);
			Logger.verifyEquals(dFrozenTime, updateTime7, "验证自动确认收货时间");

			Logger.verifyEquals(
					false,
					database.selectOrderFrozenByOrderId(orderId).get(0)
							.get("bFrozenAutoReceive"),
					"验证清关相关字段bFrozenAutoReceive");
			Logger.verifyEquals(
					false,
					database.selectOrderFrozenByOrderId(orderId).get(0)
							.get("bPause"), "验证清关相关字段");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CustomsClearanceUnfreezeOrderReq_003() {
		Logger.start(false, "物流单号列表为空,清关失败");
		try {
			List<String> logisticsNos = new ArrayList<String>();
			String deliverSummary = null;
			logisticsNos.add(deliverSummary);
			Logger.comment("前置数据准备结束");
			//参数
			customsclearanceunfreezeorderreqBean.setLogisticsNos(logisticsNos);
			//发送数据
			customsclearanceunfreezeorderreqCall
					.setData(customsclearanceunfreezeorderreqBean);
			customsclearanceunfreezeorderreqCall.callService();
			Logger.verifyEquals(ECode.SUCCESS,
					customsclearanceunfreezeorderreqCall.getCode(), "验证code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}